let View = require("View")

class LoadingView extends View
{
    open(d)
    {
        this.mRoot.zIndex = 100

        let bar = this.find('p.1').getComponent(cc.ProgressBar)
        bar.progress = 0.0
        
        let Loader = require('Loader')
        this.mLoader = new Loader()

        this.mLoader.start(d.tasks, 
            (finishNum, all) =>{

                //Log.d('loading view p: ' + finishNum + '/' + all)

                bar.progress = finishNum / all
                if (finishNum === all)
                {
                    if (d.success)
                    {
                        d.success()
                    }
                }
            }, 
            (finishNum, all) =>{

                Log.d('loading view fail, ' + finishNum + '/' + all)
                if (d.fail)
                {
                    d.fail(finishNum)
                }
            }
        )

        this.startUpdate((dt)=>{

            if (this.mLoader)
            {
                this.mLoader.run()
            }
        })
    }

    quit()
    {
        if (this.mLoader)
        {
            this.mLoader.close()
            this.mLoader = null
        }
    }
}

export default LoadingView
